#version 400

uniform sampler2D terrainTexture;

uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;

uniform float mapMultiplier;
uniform float mapBase;

in vec3 vertices;
in vec2 texCoords;

out VertexData
{
    vec3 vert;
    vec3 coords;
    vec2 texCoord;
    vec4 shadowCoord;
    float zPos;
} vertex;

void main()
{
    vec4 cleanPos = vec4(vertices.x,
                         mapBase + (texture2D(terrainTexture,texCoords).y * mapMultiplier),
                         vertices.z,1.0);
    vec4 pos = viewMatrix * cleanPos;
    vertex.vert = vertices;
    vertex.coords = pos.xyz/pos.w;
    vertex.texCoord = texCoords;
    vertex.shadowCoord = cleanPos;

    vec4 screenPosition = projectionMatrix * pos;
    gl_Position = screenPosition;
    vertex.zPos = screenPosition.z;
}
